import {
  getCategoryList
} from '../../../services/good/fetchCategoryList';

import {
  getSwiper,
  queryMasterList,
  getWorklist,
} from '../../../api/index'
Page({
  data: {
    list: [],
    masterId: '',
    addressArr: [],
    imgAddress: [],
    arr: [],
    masterInfo: '',
    baseUrl: 'https://oss.peibanmao.com/',
    array: [],
    bgi: []
  },
  init() {

  },
  onShow() {
    //this.getTabBar().init();
    this.getTabBar()
  },
  onChange(e) {
    console.log(e.currentTarget.dataset.item.id, 'this.data.masterId')
    const workId = e.currentTarget.dataset.item.id
    wx.navigateTo({
      url: `/pages/goods/itemWork/index?&id=${workId}`,
    });
  },
  onLoad(options) {
    this.init(true);
    console.log(options.id, 'options.id')
    this.setData({
      masterId: options.id
    })
    this.queryMasterListFn()
    this.getSwiperFn()
    this.getArr()
    this.getWorklistFn()
  },
  getSwiperFn() {
    return new Promise((resolve, reject) => {
      getSwiper({
        id: 25
      }).then((res) => {
        const urlsB = res.data.item.map(v => "https://oss.peibanmao.com/" + v.url);
        this.setData({

          bgi: urlsB,
        });
        resolve();
      }).catch(error => {
        reject(error);
      });
    });
  },
  getWorklistFn() {
    getWorklist({
      masterId: this.data.masterId,
      pageNum: 1,
      pageSize: 12
    }).then(res => {
      console.log(res, 'eeeeffff')
      this.setData({
        array: res.data.item || []
      })
    })
  },

  getArr() {
    const combinedArray = [];
    if (this.data.imgAddress.length = this.data.addressArr.length) {
      for (let i = 0; i < this.data.imgAddress.length && i < this.data.addressArr.length; i++) {
        combinedArray.push({
          url: this.data.imgAddress[i],
          address: this.data.addressArr[i].address
        });
      }
      return combinedArray;
    }
  },

  queryMasterListFn() {
    queryMasterList({
      pageNum: 1,
      pageSize: 10,
      masterId: this.data.masterId
    }).then(res => {
      console.log(res.data.item[0], 'res.data.item')
      this.setData({
        masterInfo: res.data.item[0]
      })
    })
  },

  //转发给朋友
  onShareAppMessage() {
    const promise = new Promise(resolve => {
      setTimeout(() => {
        resolve({
          title: '时忆旅拍'
        })
      }, 2000)
    })
    return {
      title: '时忆旅拍',
      path: '/pages/goods/item/index?id=' + this.data.masterId,
      promise
    }
  },
  //分享到朋友圈
  onShareTimeline() {},

});